<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>AOS傲雄在线</title>
    <link rel="stylesheet" href="../../layui/css/layui.css"/>
    <link rel="stylesheet" href="../../static/css/login.css"/>

    <script type="text/javascript" src="../../static/js/jquery.min.js"></script>
    <script type="text/javascript" src="../../static/js/jquery.cookie.js"></script>
    <script src="../../layui/layui.all.js" charset="utf-8"></script>
    <script src="../../static/js/base.js" charset="utf-8"></script>
    <script src="../../static/js/ax.js" charset="utf-8"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="../../static/js/html5.js"></script>
    <script src="../../static/js/respond.js"></script>
    <![endif]-->
</head>
<body>
<div class="hearder">
    <div class="logo">
        <img src="../../static/images/logo.png"/>
    </div>
    <h2>修改密码</h2>
</div>
<div class="login_wrap">
    <form class="layui-form layui-form-pane" id="from1">
        <div class="login">
            <p class="user"><span></span><input type="text" lay-verify="required|username"  name="username" id="username" placeholder="请输入用户名"/></p>
            <p class="password"><span></span><input type="text" lay-verify="required"  name="oldpassword" id="oldpassword" placeholder="请输入旧密码"/></p>
            <p class="password"><span></span><input type="text" lay-verify="required|newpassword"  name="newpassword"  id="newpassword" placeholder="请输入新密码" /></p>
            <p class="password"><span></span><input type="text"lay-verify="required|password"  name="password" id="password" placeholder="重复新密码" /></p>

            <p class="button_1"><input type="button" value="提交" lay-submit="" lay-filter="addNews" /></p>
            <p class="button_2"><input type="button" value="重置"/></p>
        </div>
    </form>
</div>

<script>
    layui.config({
        base: "js/"
    }).use(['form', 'layer', 'jquery'], function (){
        var form = layui.form;
        var layer = parent.layer === undefined ? layui.layer : parent.layer;
        var $ = layui.jquery;

        //添加验证规则
        form.verify({
            username : function(value, item) {
                var   re = /^[a-zA-Z0-9]{6,16}$/;
                var result=  re.test(value);
                if(!result) {
                    return "账号至少包含字母数字，且不少于6位";
                }
            },
            newpassword : function(value, item){
                var   re = /^[a-zA-Z0-9]{6,16}$/;
                var result=  re.test(value);
                if(!result) {
                    return "密码至少包含字母数字，且不少于6位";
                }
            },
            password : function(value, item){
                if(!new RegExp($("#newpassword").val()).test(value)){
                    return "两次输入密码不一致，请重新输入！";
                }
            }

        });

        form.on("submit(addNews)", function (data) {
            ax.post({
                type: "post",
                url: schoolWebUrl+"/user/changePassword",
                data: $("#from1").serialize(),
                contentType: "application/x-www-form-urlencoded",
                success: function (data) {
                    layer.msg(data.message);
                    if(data.code==0){
                        window.location.href="../../login.html";
                    }
                }
            });
            return false;
        });
    })
</script>
</body>
</html>
